﻿using System;
using System.Web.UI.HtmlControls;
using EPiServer.Core;

namespace EPiServer.Labs.MobilePack.Site
{
    public partial class MobileMaster : System.Web.UI.MasterPage
    {
        public virtual PageData CurrentPage { get { return ((PageBase) Page).CurrentPage; } }
        protected override void OnLoad(EventArgs e)
        {
            var startpage = MobileBase.GetSiteData(this.CurrentPage);
            CreateLinkTag("apple-touch-startup-image", startpage["StartupImage"] as string);
            CreateLinkTag("apple-touch-icon", startpage["Icon"] as string);

            this.GoogleMapsScript.Text = string.Format("<script src=\"http://maps.googleapis.com/maps/api/js?sensor=true&language={0}\"></script>", CurrentPage.LanguageBranch);
        
            base.OnLoad(e);
        }
   
        private void CreateLinkTag(string rel, string href)
        {
            HtmlLink linkTag = new HtmlLink();
            linkTag.Attributes.Add("rel", rel);
            linkTag.Href = href;
            LinkArea.Controls.Add(linkTag);
        }
    }
}
